﻿using Avalonia.Media;
using Bilibili.Common.Database;
using Bilibili.Model.User;
using PCLUntils.Objects;
using ReactiveUI;
using System.Collections.Generic;

namespace Avalonia.BiliBili.ViewModels
{
    public sealed class UserViewModel : ViewModelBase
    {
        private UserInfo _UserInfo;
        public UserInfo UserInfo
        {
            get => _UserInfo;
            set
            {
                this.RaiseAndSetIfChanged(ref _UserInfo, value);
                IsLogin = value != null;
                if (value != null && value.Data.Card.Vip.VipType != 0)
                {
                    HasVip = true;
                    HasYearVip = UserInfo.Data.Card.Vip.VipType == 2;
                }
                else
                    HasVip = false;
                GetLevelColor();
            }
        }
        private bool isSelf;
        public bool IsSelf
        {
            get => isSelf;
            set => this.RaiseAndSetIfChanged(ref isSelf, value);
        }
        private void GetLevelColor()
        {
            try
            {
                Color color = Colors.Transparent;
                if (UserInfo.IsNotEmpty())
                {
                    if (UserInfo.Data.Card.Level_Info.Current_Level <= 3)
                        color = Color.FromArgb(200, 48, 61, 255);
                    else
                    {
                        if (UserInfo.Data.Card.Level_Info.Current_Level <= 6)
                            color = Color.FromArgb(200, 255, 48, 48);
                        else
                            color = Color.FromArgb(200, 255, 199, 45);
                    }
                }
                LevelColor = new SolidColorBrush(color);
            }
            catch { }
        }
        private bool isLogin;
        public bool IsLogin
        {
            get => isLogin;
            private set => this.RaiseAndSetIfChanged(ref isLogin, value);
        }
        private bool hasVip;
        public bool HasVip
        {
            get => hasVip;
            set => this.RaiseAndSetIfChanged(ref hasVip, value);
        }
        private bool hasYearVip;
        public bool HasYearVip
        {
            get => hasYearVip;
            set => this.RaiseAndSetIfChanged(ref hasYearVip, value);
        }
        private SolidColorBrush levelColor;
        public SolidColorBrush LevelColor
        {
            get => levelColor;
            set => this.RaiseAndSetIfChanged(ref levelColor, value);
        }
        private List<UserInfo> followBangmis = [];
        public List<UserInfo> FollowBangmis
        {
            get => followBangmis;
            set => this.RaiseAndSetIfChanged(ref followBangmis, value);
        }
        public void SetUserInfo(UserInfo userInfo = null)
        {
            userInfo ??= SettingHelper.UserInfo;
            UserInfo = userInfo;
        }
    }
}